﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Crank.Core
{
    public class StringLineProvider : ILineProvider
    {
        private TextReader _reader;
        private string NextLine;

        public StringLineProvider(string source)
        {
            _reader = new StreamReader(new MemoryStream(ASCIIEncoding.ASCII.GetBytes(source)));
            ReadNextLine();
        }

        private void ReadNextLine()
        {
            NextLine = _reader.ReadLine();
            HasLines = NextLine != null;
        }

        #region ILineProvider Members

        public bool HasLines { get; protected set; }

        public string GetNextLine()
        {
            if (!HasLines)
                return null;
            var next_line = NextLine;
            ReadNextLine();
            return next_line;
        }

        #endregion
    }
}
